import * as BaseApi from './BaseApi.js';


import * as Config from './Config.js';

export const queryCatTree = (self) => {

  let data = {
    merchantId: self.$store.getters.getMerchantId
  }
  return BaseApi.requestForm(Config.g_service_url, '/merchant/cattree', data)
    .then(res => res)

}



export const addGoods = (model) => {

  return BaseApi.requestForm(Config.g_biz_url, '/goods/manager/add', model)
    .then(res => res)


}


export const updateGoods = (model) => {

  return BaseApi.requestForm(Config.g_biz_url, '/goods/manager/update', model)
    .then(res => res)


}

export const onLineStatusUpdate = (model) => {
  return BaseApi.requestForm(Config.g_biz_url, '/goods/manager/updatestatus', model)
    .then(res => res)
}
// 批量删除商品
export const batchDelete = (model) => {
  return BaseApi.requestForm(Config.g_biz_url, '/goods/manager/batchDelete', model)
    .then(res => res)
}
// 批量导出商品
export const onBatchExport = (model) => {
	console.log(model)
  return BaseApi.requestForm(Config.g_biz_url, '/batchExport', model)
    .then(res => res)
}
// 上传封面
export const uploadImg = (model) =>{
	console.log(model)
	console.log(JSON.stringify(model))
	return BaseApi.uploadImg(Config.g_biz_url, '/upload/img', model)
    .then(res => res)
}
// 上传
export const uploadMitImg = (model) =>{
	console.log(model)
	console.log(JSON.stringify(model))
	return BaseApi.uploadImg(Config.g_upload_url, '', model)
    .then(res => res)
}
// 导入excel
export const uploadExcel = (model) =>{
	console.log(model)
	console.log(JSON.stringify(model))
	return BaseApi.uploadImg('http://116.62.22.58:8030/bapi', '/batchImport', model)
    .then(res => {
    	console.log(res)
    	res
    }).catch(err =>{
    	console.log(err)
    return	new Promise((re,reject) => {
    		reject(err)
    	})
    })
}


export const queryGoods = (self, params) => {
  params.token = self.$store.getters.getToken
  params.merchantUserId=self.$store.getters.getModel.merchantUserId

  return BaseApi.requestForm(Config.g_biz_url, '/goods/manager/query', params)
    .then(res => res)
}
// 添加店铺
export const addStore = (self, params) => {
	let storage = window.sessionStorage;
  params.merchantId = storage.getItem("merchantId");
  
  return BaseApi.requestForm(Config.g_biz_url, '/merchant/shop/add', params)
    .then(res => res)
}
// 获取店铺列表
export const getStoreList = (self, params) => {
  let storage = window.sessionStorage;
  params.merchantId = storage.getItem("merchantId");
//params.token = self.$store.getters.getToken
	
	params.token = storage.getItem('storeToken') 
  return BaseApi.requestForm(Config.g_biz_url, '/merchant/shop/list', params)
    .then(res => res)
}
// 删除店铺列表
export const deleteStore = (self, params) => {
	let storage = window.sessionStorage;
  params.merchantId = storage.getItem("merchantId");
//params.token = self.$store.getters.getToken
  params.token = storage.getItem('storeToken') 
  return BaseApi.requestForm(Config.g_biz_url, '/merchant/shop/delete', params)
    .then(res => res)
}

// 获取修理工审核
export const getRepairList = (self, params) => {
	let storage = window.sessionStorage;
  params.merchantId = storage.getItem("merchantId");
//params.token = self.$store.getters.getToken
  params.token = storage.getItem('storeToken') 
  return BaseApi.requestForm(Config.g_biz_url, '/merchant/repair/list', params)
    .then(res => res)
}

// 删除修理工
export const deleteRepair = (self, params) => {
  params.merchantUserId=self.$store.getters.getModel.merchantUserId
//params.token = self.$store.getters.getToken
  params.token = storage.getItem('storeToken') 
  return BaseApi.requestForm(Config.g_biz_url, '/merchant/repair/delete', params)
    .then(res => res)
}
// 修理工审核
export const updateRepair = (self, params) => {
	let storage = window.sessionStorage;
  params.merchantId = storage.getItem("merchantId");
  params.merchantUserId=self.$store.getters.getModel.merchantUserId
//params.token = self.$store.getters.getToken
  params.token = storage.getItem('storeToken') 
  return BaseApi.requestForm(Config.g_biz_url, '/merchant/repair/update', params)
    .then(res => res)
}



// 保养列表
export const getPlanList = (self, params) => {
	let storage = window.sessionStorage;
  params.merchantUserId = storage.getItem("merchantUserId");
	params.token = self.$store.getters.getToken
	console.log(params)
	console.log(555)
  return BaseApi.requestForm(Config.g_biz_url, '/maintenance/plan/list', params)
    .then(res => res)
}


// 删除保养列表
export const linkDelete = (self, params) => {
	let storage = window.sessionStorage;
  params.merchantUserId = storage.getItem("merchantUserId");
	params.token = self.$store.getters.getToken
	console.log(params)
	console.log(666)
  return BaseApi.requestForm(Config.g_biz_url, '/maintenance/plan/delete', params)
    .then(res => res)
}




// 导入保养数据



export const planImport = (model) =>{
	console.log(model)
	console.log(JSON.stringify(model))
	return BaseApi.uploadImg('http://116.62.22.58:8050/bizapi', '/maintenance/plan/import', model)
    .then(res => {
    	console.log(res)
    	
    	return new Promise((reslove, reject) => {
    		reslove(res)
    	})
    }).catch(err =>{
    	console.log(err)

	    return	new Promise((re,reject) => {
	    		reject(err)
	    	})
	    })
}


// 保存保养数据 /maintenance/plan/add

export const planAdd = (self, params) => {
	let storage = window.sessionStorage;
  params.merchantUserId = storage.getItem("merchantUserId");
	params.token = self.$store.getters.getToken
	console.log(params)
	console.log(666)
  return BaseApi.requestForm(Config.g_biz_url, '/maintenance/plan/add', params)
    .then(res => res)
}

// 获取施工列表数据
export const getRecordList = (self, params) => {
	let storage = window.sessionStorage;
  params.merchantId = storage.getItem("merchantId");
//params.token = self.$store.getters.getToken
  params.token = storage.getItem('storeToken') 
  return BaseApi.requestForm(Config.g_biz_url, '/construction/record/list', params)
    .then(res => res)
}
// 删除施工列表
export const deleteRecord = (self, params) => {
	let storage = window.sessionStorage;
  params.merchantId = storage.getItem("merchantId");
//params.token = self.$store.getters.getToken
  params.token = storage.getItem('storeToken') 
  return BaseApi.requestForm(Config.g_biz_url, '/construction/record/delete', params)
    .then(res => res)
}

// 编辑施工列表
export const updateRecord = (self, params) => {
	let storage = window.sessionStorage;
  params.merchantId = storage.getItem("merchantId");
//params.token = self.$store.getters.getToken
  params.token = storage.getItem('storeToken') 
  params.merchantUserId=self.$store.getters.getModel.merchantUserId
  return BaseApi.requestForm(Config.g_biz_url, '/construction/record/update', params)
    .then(res => res)
}


// 更新地址
export const updateStore = (self, params) => {
	let storage = window.sessionStorage;
  params.merchantId = storage.getItem("merchantId");
  return BaseApi.requestForm(Config.g_biz_url, '/merchant/shop/update', params)
    .then(res => res)
}

export const queryGoodsDetail = (goodsId) => {

  let data = {
    goodsId: goodsId
  }

  return BaseApi.requestGet(Config.g_biz_url, '/goods/detail', data)
    .then(res => res)


}


export const queryMemberPrice = (self, goodsId) => {

  let data = {
    goodsId: goodsId,
    token: self.$store.getters.getToken,
    merchantUserId: self.$store.getters.getModel.merchantUserId
  }

  return BaseApi.requestForm(Config.g_biz_url, '/goods/memberprice/query', data)
    .then(res => res)

}

export const updateMemberPrice = (self, model, goodsId) => {
  console.log(',,,', model)
  let data = {
    token: self.$store.getters.getToken,
    merchantUserId: self.$store.getters.getModel.merchantUserId,

    goodsId: goodsId,

    ownerPrice: model.ownerPrice,
    agentPrice: model.agentPrice,
    star3Price: model.star3Price,
    star4Price: model.star4Price,
    star5Price: model.star5Price

  }

  return BaseApi.requestForm(Config.g_biz_url, '/goods/memberprice/update', data)
    .then(res => res)

}



export const queryGoodsCarLink = (self, goodsId) => {

  let data = {
    goodsId: goodsId,
    token: self.$store.getters.getToken,
    merchantId: self.$store.getters.getMerchantId
  }

  return BaseApi.requestForm(Config.g_biz_url, '/goods/car/linkquery', data)
    .then(res => res)
}



export const handleDelete = (self, data) => {



  return BaseApi.requestForm(Config.g_biz_url, '/goods/manager/delete', data)
    .then(res => res)
}


export const changeCategory = (model) => {
  console.log(model)
  return BaseApi.requestForm(Config.g_biz_url, '/goods/category/update', model)
    .then(res => res)
}



export const getPdAttribute = (self, model) => {

  Object.assign(model, {
    token: self.$store.getters.getToken,
    merchantUserId: self.$store.getters.getModel.merchantUserId
  });
  return BaseApi.requestForm(Config.g_biz_url, '/goods/attribute/query', model)
    .then(res => res)
}

export const changePdAttribute = (self, model) => {

  Object.assign(model, {
    token: self.$store.getters.getToken,
    merchantUserId: self.$store.getters.getModel.merchantUserId
  });
  return BaseApi.requestForm(Config.g_biz_url, '/goods/attribute/update', model)
    .then(res => res)
}

export const addPdAttribute = (self, model) => {

  Object.assign(model, {
    token: self.$store.getters.getToken,
    merchantUserId: self.$store.getters.getModel.merchantUserId
  });
  return BaseApi.requestForm(Config.g_biz_url, '/goods/attribute/add', model)
    .then(res => res)
}
export const delPdAttribute = (self, model) => {
  
    Object.assign(model, {
      token: self.$store.getters.getToken,
      merchantUserId: self.$store.getters.getModel.merchantUserId
    });
    return BaseApi.requestForm(Config.g_biz_url, '/goods/attribute/delete', model)
      .then(res => res)
  }

export const unit = () => {
    return BaseApi.requestGet(Config.g_biz_url, '/goods/unit')
      .then(res => res)
  }
  